package com.factory.iamp.utils.helper;

import com.factory.iamp.utils.exception.APIException;
import lombok.Getter;

@Getter
public enum CheckTypeCode {
    SelfCheck(1, "{AllBase}", "Scheck", "自检"),
    OtherCheck(2, "SCheck", "Ocheck", "互检"),
    ZCheck(3, "OCheck", "Zcheck", "Z检");
    private int code;
    private String pre;
    private String base;
    private String name;

    CheckTypeCode(int code, String pre, String base, String name) {
        this.code = code;
        this.pre = pre;
        this.base = base;
        this.name = name;
    }

    public static CheckTypeCode makeTypeCode(int type) {
        if(type == 1) return CheckTypeCode.SelfCheck;
        if(type == 2) return CheckTypeCode.OtherCheck;
        if(type == 3) return CheckTypeCode.ZCheck;
        throw new APIException(ResponseCode.VALIDATE_FAILED, "质检类型不存在");
    }

    public static int NameToCode(String name) {
        if(name.equals("Scheck")) return CheckTypeCode.SelfCheck.code;
        if(name.equals("Ocheck")) return CheckTypeCode.OtherCheck.code;
        if(name.equals("Zcheck")) return CheckTypeCode.ZCheck.code;
        throw new APIException(ResponseCode.VALIDATE_FAILED, "质检类型不存在");
    }
}
